package com.eip.zd.controller;

import com.eip.zd.common.Result;
import com.eip.zd.entity.Price;
import com.eip.zd.service.PriceService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/price")
public class PriceController {
    @Resource
    private PriceService priceService;

    @GetMapping("/getPriceList")
    public Result getPriceList(@RequestParam(required = false) String keyword) {
        List<Price> priceList = priceService.getPriceList(keyword);
        return Result.success(priceList);
    }

    @GetMapping("/getHisPriceList/{custId}")
    public Result getHisPriceList(@PathVariable(required = false) String custId) {
        List<Price> priceList = priceService.getHisPriceList(custId);
        return Result.success(priceList);
    }

    @PostMapping("/add")
    public Result addPrice(@RequestBody Price price) {
        priceService.add(price);
        return Result.success();
    }

    @PostMapping("/update")
    public Result updatePrice(@RequestBody Price price) {
        priceService.update(price);
        return Result.success();
    }

    @PostMapping("/remove/{id}")
    public Result removePrice(@PathVariable Long id) {
        priceService.remove(id);
        return Result.success();
    }

    @PostMapping("/ifUse/{id}")
    public Result ifUse(@PathVariable Long id) {
        priceService.ifUse(id);
        return Result.success();
    }
}
